package com.zima.mall.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.assertj.core.util.DateUtil;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("created", DateUtil.now(), metaObject);
        this.setFieldValByName("updated", DateUtil.now(), metaObject);
        this.setFieldValByName("create_time",DateUtil.now(),metaObject);
        this.setFieldValByName("update_time",DateUtil.now(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updated", DateUtil.now(), metaObject);
        this.setFieldValByName("update_time",DateUtil.now(),metaObject);
    }
}